package com.atwulidun.observer16;

// 观察者接口
public interface Observer {
    // 更新观察者属性的方法
    void update(int temperature, int humidity, int pressure);

    // 更新观察者属性后发布属性的方法
    void display();
}

// 观察者的具体实现类
// 百度新闻
class BaiDu implements Observer {
    // 温度
    private int temperature;
    // 湿度
    private int humidity;
    // 气压
    private int pressure;

    @Override
    public void update(int temperature, int humidity, int pressure) {
        this.temperature = temperature;
        this.humidity = humidity;
        this.pressure = pressure;
        display();
    }

    @Override
    public void display() {
        System.out.println("百度推送：温度为" + temperature);
        System.out.println("百度推送：湿度度为" + humidity);
        System.out.println("百度推送：气压为" + pressure);
    }
}
// 新浪新闻
class Sina implements Observer {
    // 温度
    private int temperature;
    // 湿度
    private int humidity;
    // 气压
    private int pressure;

    @Override
    public void update(int temperature, int humidity, int pressure) {
        this.temperature = temperature;
        this.humidity = humidity;
        this.pressure = pressure;
        display();
    }

    @Override
    public void display() {
        System.out.println("新浪推送：温度为" + temperature);
        System.out.println("新浪推送：湿度度为" + humidity);
        System.out.println("新浪推送：气压为" + pressure);
    }
}
